function dosearchpaket(xAwal) {
    xSearch = "";
    try
    {
        if ($("#edSearch").val() != "") {
            xSearch = $("#edSearch").val();
        }
    } catch (err) {
        xSearch = "";
    }
    if (typeof (xSearch) == "undefined") {
        xSearch = "";
    }
    $(document).ready(function() {
        $.ajax({
            url: getBaseURL() + "index.php/ctrpaket/searchpaket/",
            data: "xAwal=" + xAwal + "&xSearch=" + xSearch,
            cache: false,
            dataType: 'json',
            type: 'POST',
            success: function(json) {
                $("#tabledatapaket").html(json.tabledatapaket);
            },
            error: function(xmlHttpRequest, textStatus, errorThrown) {
                alert("Error juga" + xmlHttpRequest.responseText);
            }
        });
    });
}

function doeditpaket(edidx) {
    $(document).ready(function() {
        $.ajax({
            url: getBaseURL() + "index.php/ctrpaket/editrecpaket/",
            data: "edidx=" + edidx,
            cache: false,
            dataType: 'json',
            type: 'POST',
            success: function(json) {
                $("#edidx").val(json.idx);
                $("#ednamapaket").val(json.namapaket);
                $("#edharga").val(json.harga);
                $("#eddate_mulai").val(json.date_mulai);
                $("#eddate_akhir").val(json.date_akhir);
                $("#edidpegawai").val(json.idpegawai);
            },
            error: function(xmlHttpRequest, textStatus, errorThrown) {
                alert("Error juga " + xmlHttpRequest.responseText);
            }
        });
    });
}

function doClearpaket() {
    $(document).ready(function() {
        $("#edidx").val("0");
        $("#ednamapaket").val("");
        $("#edharga").val("");
        $("#eddate_mulai").val("");
        $("#eddate_akhir").val("");
        $("#edidpegawai").val("");
    });
}

function dosimpanpaket() {
    $(document).ready(function() {
        $.ajax({
            url: getBaseURL() + "index.php/ctrpaket/simpanpaket/",
            data: "edidx=" + $("#edidx").val() + "&ednamapaket=" + $("#ednamapaket").val() + "&edharga=" + $("#edharga").val() + "&eddate_mulai=" + $("#eddate_mulai").val() + "&eddate_akhir=" + $("#eddate_akhir").val() + "&edidpegawai=" + $("#edidpegawai").val(),
            cache: false,
            dataType: 'json',
            type: 'POST',
            success: function(msg) {
                doClearpaket();
                dosearchpaket('-99');
                alert("Data Berhasil Disimpan.... ");
            },
            error: function(xmlHttpRequest, textStatus, errorThrown) {
                alert("Error juga " + xmlHttpRequest.responseText);
            }
        });
    });
}

function dohapuspaket(edidx, ednamapaket) {
    if (confirm("Anda yakin Akan menghapus data " + ednamapaket + "?"))
    {
        $(document).ready(function() {
            $.ajax({
                url: getBaseURL() + "index.php/ctrpaket/deletetablepaket/",
                data: "edidx=" + edidx,
                cache: false,
                dataType: 'json',
                type: 'POST',
                success: function(json) {
                    doClearpaket();
                    dosearchpaket('-99');
                },
                error: function(xmlHttpRequest, textStatus, errorThrown) {
                    alert("Error juga " + xmlHttpRequest.responseText);
                }
            });
        });
    }
}


dosearchpaket(0);
function strpad(val) {
    return (!isNaN(val) && val.toString().length == 1) ? "0" + val : val;
}
function settanggal() {

    $(document).ready(function() {


        var currentTimeAndDate = new Date();
        var Date30 = new Date();
        var date = new Date();
        Date30.setDate(Date30.getDate() - 30);



        var dd = date.getDate();
        var mm = date.getMonth();
        var yy = date.getYear();

        var hh = date.getHours();
        var mnt = date.getMinutes();

        var dd30 = Date30.getDate();
        var mm30 = Date30.getMonth();
        var yy30 = Date30.getYear();

        yy = (yy < 1000) ? yy + 1900 : yy;
        yy30 = (yy30 < 1000) ? yy30 + 1900 : yy30;



        $("#eddate_mulai").datepicker({
            //dateFormat: 'yy-mm-dd'
            dateFormat: 'dd-mm-yy'
        });

        $("#eddate_mulai").val(strpad(dd) + "-" + strpad(mm + 1) + "-" + yy);

       $("#eddate_akhir").datepicker({
            //dateFormat: 'yy-mm-dd'
            dateFormat: 'dd-mm-yy'
        });

        $("#eddate_akhir").val(strpad(dd) + "-" + strpad(mm + 1) + "-" + yy);

    });
}

settanggal();
